package com.atguigu.controller;

import com.atguigu.pojo.Result;
import com.atguigu.pojo.vo.ScheduleVo;
import com.atguigu.service.ScheduleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/schedule")
@CrossOrigin
public class ScheduleController {

    @Autowired
    private ScheduleService scheduleService ;


    @GetMapping
    public Result findAll(){
        List<ScheduleVo> scheduleVos = scheduleService.findAll();
        return new Result(200,true,scheduleVos);

    };


    @DeleteMapping("/{id}")
    public Result deleteById(@PathVariable("id") Integer id){
        scheduleService.removeScheduleById(id);
        return new Result(200,true,null);

    }


    @PostMapping
    public Result addSchedule(@RequestBody ScheduleVo scheduleVo){
        scheduleService.addSchedule(scheduleVo);


        return new Result(200,true,null);
    }


    @PutMapping
    public Result updateScheduleById( @RequestBody ScheduleVo scheduleVo){
        scheduleService.updateById(scheduleVo);
        return new Result(200,true,null);

    }
}
